<?php
/**
 * Nordic Repository
 * 
 * LICENSE
 * 
 * The new BSD license is applied on this source-file. For further
 * information please visit http://license.nordic-dev.de/newbsd.txt
 * or send an email to andre.moelle@gmail.com.
 */

/**
 * This class works as factory for creating filters.
 * 
 * @category   Nordic
 * @package    Nordic_Filter
 * @copyright  2007 Nordic Development
 * @license    http://license.nordic-dev.de/newbsd.txt (New-BSD license)
 * @author     Andre Moelle <andre.moelle@gmail.com>
 * @version    $Id: Filter.php 3 2007-07-08 09:21:42Z andre.moelle $
 */
class Nordic_Upload_Filter
{
	/**
	 * Returns the name of the filter passed by arguments.
	 * 
	 * @param String $filter filter-name
	 */
	private static function _createName ($filter)
	{
		return __CLASS__ . '_' . $filter;
	}
	
	/**
	 * Returns if the given filter exists.
	 * 
	 * @param String $filter filter-name
	 * @return Boolean
	 */
	public static function checkFilter ($filter)
	{
		try
		{
			Zend_Loader::loadClass(self::_createName($filter));
			
			return true;
		}
		catch (Zend_Exception $e)
		{
			return false;
		}
	}
	
	/**
	 * Creates and returns a filter-class.
	 * 
	 * @param String $filter type of filter-class
	 * @return Nordic_Upload_Filter_Interface
	 */
	public static function factory ($filter, $source)
	{
		$class = self::_createName($filter);
		Zend_Loader::loadClass($class);
		
		return new $class($source);
	}
}
?>